package cn.hd.controller;

import cn.hd.entity.Power;
import cn.hd.entity.Result;
import cn.hd.service.PowerService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
public class PowerController {
    @Autowired
    private PowerService powerService;

    @RequestMapping("/selectPowers")
    public Object selectPowers(int pagenum,int pagesize,String name){
        Map map = new HashMap();
        map.put("name",name);
        PageInfo<Power> page = powerService.selectPowers(pagenum, pagesize, map);
        if (page.getList().size() == 0){
            return  new Result("400","查无此人",null);
        }else {
            return  new Result("200","查询成功",page);
        }
    }

    @RequestMapping("/selectOneTwoPower")
    public Object selectOneTwoPower(){
        List<Power> powers = powerService.selecyOneTwoPower();
        return new Result("200","查询成功",powers);
    }


    @RequestMapping("/selectPowerbyUid")
    public Object selectPowerbyUid(int id){
        List<Power> powers = powerService.selectPowerbyUid(id);
        return new Result("200","查询成功",powers);
    }
}
